#!/bin/bash
source include_bench.sh

do_bench_wcet() {
	echo "LD_PRELOAD=$1 $2"
	${NICE} ${PERF} env LD_PRELOAD=$1 $2 1> ./log/wcet.tsv 2> ./log/tmp.tsv
	cat ./log/wcet.tsv
	percen=`cat ./log/wcet.tsv | tail -n1`
	echo "$3 ${percen}" >> ./log/result_wcet.tsv
	sleep 1
}

# backup 
mv ./log/result_wcet.tsv ./log/result_wcet_old.tsv

${curpath}/build/gtest_basic_wcet.o 1> ./log/wcet.tsv
hd=`cat ./log/wcet.tsv | head -n1`
echo "lib ${hd}" > ./log/result_wcet.tsv



trap "exit" INT
echo "run ${1} x 2 times (gcc + clang)" 
for ((i=1;i<=${1};i++))
do
	for lib in ${wcetliblist}   
	do
		do_bench_wcet ${curpath}/build_lib/glibapfsds_${lib}.so ${curpath}/build/gtest_basic_wcet.o ${lib} ./log/result.tsv
		do_bench_wcet ${curpath}/build_lib/cllibapfsds_${lib}.so ${curpath}/build/cltest_basic_wcet.o ${lib} ./log/result.tsv
	done
done

# cd script
# python3 geomean.py ../log/result.tsv
